<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">

            <fieldset class="table-search-fieldset">
                <legend>搜索信息</legend>
                <div style="margin: 10px 10px 10px 10px">
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">日期范围</label>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="date_begin" id="date" lay-verify="date"
                                        placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input"
                                        value="2022-01-01">
                                </div>
                                <div class="layui-form-mid">-</div>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="date_end" id="date-end" lay-verify="date"
                                        placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input"
                                        value="">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">学校</label>
                                <div class="layui-input-inline">
                                    <select name="school" lay-search="" id="school">
                                        <option value="">直接选择或搜索选择</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">项目</label>
                                <div class="layui-input-block">
                                    <input type="text" name="club" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">姓名</label>
                                <div class="layui-input-block">
                                    <input type="text" name="name" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            </div>
                        </div>
                    </form>
                </div>
            </fieldset>


            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

            <script type="text/html" id="currentTableBar">
                <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="revoke">审核失败</a>
            </script>

        </div>
    </div>
    <script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="../js/lay-config.js?v=2.0.0" charset="utf-8"></script>
    <script>
        layui.use(['form', 'table', 'laydate', 'cookie'], function () {
            var laydate = layui.laydate;

            //执行一个laydate实例
            //日期
            laydate.render({
                elem: '#date',
            });
            laydate.render({
                elem: '#date-end',
            });
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table;
            //超时跳转
            $.ajaxSetup({
                complete: function (XMLHttpRequest, textStatus) {
                    if (textStatus == "parsererror") {
                        //这里不能用window.location,href，因为用了之后你会发现他是在子窗口跳转到登录页，而不是整个系统跳转
                        top.location.href = '../../views/login.html';
                    }
                }
            })
            // 初始化表格
            var tableIns = table.render({
                elem: '#currentTableId',
                url: '/payment/pass',
                where: {
                    role: $.cookie("role"),
                    schools: $.cookie("schools")
                },
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                cols: [
                    [{
                            width: 50,
                            type: 'numbers',
                            title: '序号',
                            fixed: "left",
                        },
                        {
                            field: 'school',
                            width: 200,
                            title: '学校',
                            sort: true
                        },
                        {
                            field: 'club',
                            width: 200,
                            title: '项目',
                        },
                        {
                            field: 'grade',
                            width: 80,
                            title: '年级',
                            align: "center"
                        },
                        {
                            field: 'class_name',
                            width: 60,
                            title: '班级',
                            align: "center"
                        },
                        {
                            field: 'name',
                            width: 90,
                            title: '学生姓名',
                            align: "center"
                        },
                        {
                            field: 'nickname',
                            width: 130,
                            title: '微信昵称',
                            align: "center",
                            templet:function(d){
                                return decodeURIComponent(d.nickname);
                            }
                        },
                        {
                            field: 'mobile',
                            width: 130,
                            title: '联系电话',
                            align: "center"
                        },
                        {
                            field: 'amount',
                            width: 130,
                            title: '缴费金额',
                            align: "center"
                        },
                        {
                            // field: 'pay_img_url',
                            width: 90,
                            title: '支付截图',
                            align: "center",
                            templet: function (d) {
                                var url = d.pay_img_url;
                                return '<img src="' + url +
                                    '" style="height:40px;border:0.1px solid #d2d2d2" title="点击查看" onclick="showBigImage(this)"/>';
                            }
                        },
                        {
                            field: 'tip',
                            width: 130,
                            title: '备注',
                            align: "center"
                        },
                        {
                            field: 'pay_time',
                            width: 160,
                            title: '提交时间',
                            sort: true,
                            align: "center"
                        },
                        {
                            field: 'staff_name',
                            width: 90,
                            title: '审核人',
                            align: "center"
                        },
                        {
                            title: '操作',
                            minWidth: 150,
                            toolbar: '#currentTableBar',
                            align: "center",
                            fixed: "right"
                        }
                    ]
                ],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 10,
                page: true
            });
            $(function() {// 给下拉学校填充数据
                // 格式化当前时间
                function completeDate(value) {
                    return value < 10 ? "0" + value : value;
                }
                var char = "-";
                var nowDate = new Date();
                var day = nowDate.getDate() + 1;
                var month = nowDate.getMonth() + 1; //注意月份需要+1
                var year = nowDate.getFullYear();
                //补全0，并拼接
                var nowdate = year + char + completeDate(month) + char + completeDate(day);
                $("#date-end").val(nowdate);
                if($.cookie("role")==0){
                    var data= $.cookie("schools").split(',');
                    $('#school').empty();
                        $('#school').append(new Option("请选择学校", ''));
                        $.each(data, function (index, value) {
                            // 前者是页面显示的值，后者是传递给后台的值。
                            $('#school').append(new Option(value, value)); // 下拉菜单里添加元素
                        });
                        //渲染select
                        return form.render('select');
                }
                $.get('/club/school',function(data){
                    var data=data.data;
                        $('#school').empty();
                        $('#school').append(new Option("请选择学校", ''));
                        $.each(data, function (index, value) {
                            // 前者是页面显示的值，后者是传递给后台的值。
                            $('#school').append(new Option(value.s_name, value.s_name)); // 下拉菜单里添加元素
                        });
                        //渲染select
                        form.render('select');
                })
            })
            // 点击大图
            showBigImage = function (e) {
                layer.open({
                    type: 1,
                    title: false,
                    closeBtn: 0,
                    resize:false,
                    shadeClose: true, //点击阴影关闭
                    area: ['280px'], //宽高
                    content: "<img src=" + $(e).attr('src') + " width='100%' height='100%'/>"
                });
            }
            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                var result = JSON.stringify(data.field);
                // 执行搜索重载
                table.reload('currentTableId', {
                    page: {
                        curr: 1
                    },
                    where: {
                        role: $.cookie("role"),
                        schools: $.cookie("schools"),
                        searchParams: result
                    }
                }, 'data');

                return false;
            });

            table.on('tool(currentTableFilter)', function (obj) {
                var data = obj.data;
                var json = {
                    "id": data.id,
                    "staff_name": $.cookie("name"),
                    "flag":2
                };
                    json = JSON.stringify(json);
                    layer.confirm('确定审核失败？', function (index) {
                        $.ajax({
                            url: '/payment/check',
                            method: "PUT",
                            data: json,
                            contentType: "application/json",
                            error: function (err) {
                                layer.msg(err.msg, {
                                    icon: 2
                                });
                            }
                        })
                        // tableIns.reload();
                        obj.del();
                        layer.close(index);
                    });
            });

        });
    </script>
</body>

</html>